# -*- coding:utf-8 -*-

from fastapi import Depends, HTTPException, status
from fastapi.security import SecurityScopes

from app.models.request.role import Role, Permision, RolePersision
from app.repository.role import RoleRepository

class RoleService:
    def __init__(self, repo: RoleRepository=Depends(RoleRepository)):
        self.repo = repo

    async def get_role_persision_by_role_ids(self, role_ids: list[int])->list[RolePersision]:
        roles= await self.repo.get_by_ids(role_ids)
        persitions = await self.get_persision_by_role_ids(role_ids)
        roles = [RolePersision.from_orm(role) for role in roles]
        for role in roles:
            role.persitions = persitions[role.id]
        return roles
    
    async def get_persision_by_role_ids(self, role_ids: list[int]):
        return await self.repo.get_ref_by_ids(role_ids, "tb_permision", "role_permision", Permision)